//
//  AAFileReader.m
//  AnimAPI
//
//  Created by Alécio José Gomes Neto on 24/03/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "AAFileReader.h"
#import "AADefs.h"

@implementation AAFileReader

- (AAAnimation*) loadAnimationFromFile:(NSString*) path {
    
    return nil;
}

    /*
    CFReadStreamRef anmFile = CFReadStreamCreateWithFile(kCFAllocatorDefault, (CFURLRef) path );
    
    if(!CFReadStreamOpen(anmFile)) {
        
    }
    
    // cria um header
    struct AA_ANIMATION_HEADER animationHeader;
    memset(&animationHeader, 0, sizeof(animationHeader));
    
    // le o header de controle
    CFReadStreamRead(anmFile, (void*)&animationHeader, sizeof(animationHeader));
    
    // agora já sabe-se a quantidade de animações
    struct AA_ANIMATION_BLOCK *animationBlocks = malloc(sizeof(struct AA_ANIMATION_BLOCK) * animationHeader.animationQty);
    
    // começa a maracutaia
    struct AA_ANIMATION_BLOCK animationBlock;
    for (int i = 0; i < animationHeader.animationQty; i++) {
        memset(&animationBlock, 0, sizeof(animationBlock));
        
        CFReadStreamRead(anmFile, (void*)&animationBlock, sizeof(animationBlock));
        animationBlocks[i] = animationBlock;
    }
    
    for (int i = 0; i < animationHeader.imagesQty; i++) {
        // quantidade de bytes da imagem
        NSInteger imgCB;    
        CFReadStreamRead(anmFile, (void*)&imgCB, sizeof(imgCB));
        
        Byte* buf = malloc(imgCB);
        CFReadStreamRead(anmFile, buf, imgCB);
        
        NSData *data = [[NSData alloc] initWithBytes:buf length:imgCB];
        free(buf);
        
        AAAnimation *animation = [[AAAnimation alloc] initWithType:(AAAnimationType)animationBlocks[0].idAnimation 
                                                          andValue:animationBlocks[0].animationValue
                                                           andTime:animationBlocks[0].animationTime];
        
        [animation setAnimationImageForData:data];
        [data release];
        free(animationBlocks);
        
        return animation;
    }
    
    return nil;
}*/

@end
